import 'element-plus/dist/index.css'

import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import store from '@/store'
import request from '@/utils/request'
import routes from '@/router/index'
import App from './App.vue'
import storage from './utils/storage'

const app = createApp(App)

app.config.globalProperties.$request = request

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.directive('has', {
  beforeMount: (el, binding) => {
    console.log('has', el, binding);
    const { arg, value } = binding;
    let actionList = storage.getItem('actionList');
    let hasPermission = actionList.includes(value)
    if (!hasPermission) {
      el.style.display = 'none';
      setTimeout(() => {
        el.parentNode.removeChild(el);
      }, 0)
    }
  }
})

app.use(ElementPlus, { size: 'small' })
app.use(routes)
app.use(store)
app.mount('#app')
